package com.zymail.controller;

import java.util.List;

import com.zymail.exception.ExceptionMessage;
import com.zymail.service.GoodsCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zymail.api.CommonResult;
import com.zymail.api.ResultCode;
import com.zymail.bean.ZyClass;
import com.zymail.vo.GoodsCategory;

@Controller
@RequestMapping("/goods/cate")
public class GoodsCategoryController {

    @Autowired
    private GoodsCategoryService goodsCategoryService;
    @PostMapping("/all")
    @ResponseBody
    public CommonResult<List<GoodsCategory>> goodsAllCates() {
        try {
            List<GoodsCategory> categories = goodsCategoryService.getGoodsCategories();
            return new CommonResult<>(ResultCode.SUCCESS, categories);
        } catch (NullPointerException e) {
            ExceptionMessage em = new ExceptionMessage(e);
            return new CommonResult<>(ResultCode.FAILED, null, e.getMessage() + em.getMsg());
        } catch (Exception e) {
            // 记录日志
            return new CommonResult<>(ResultCode.FAILED, null, "加载分类数据出错！");
        }
    }
}
